<?php
class ShopGalleryImage extends DataObject {
    static $db = array(
	'Title' => 'Varchar(150)'
    );
   
    static $has_one = array(
        'Image' => 'ShopGalleryImage_Image',
        'Shop' => 'Shop'
    );
   
    static $field_names = array(
	'Image' => 'Afbeelding',
	'Title' => 'Titel'
    );
    
    static $summary_fields = array(
	'Title' => 'Titel'
    );
   
    function getCMSFields_forPopup() {
      
	$fields = new FieldSet(
            new TextField('Title', 'Titel'),
            new ImageField('Image', 'Afbeelding')		
	);
        return $fields;
    }
    
    public function canView($member = null) {
        return true;
    }
    
    public function canCreate($member = null) {
        if(!$member) $member = Member::currentUser();
        if(!$member) return false;
        return (
            Permission::checkMember($member, 'ADMIN')
            || Permission::checkMember($member, 'MANAGE_SHOPS')
        );
    }
    
    public function canEdit($member = null) {
        return $this->canCreate($member);
    }
 
    public function canDelete($member = null) {
        return $this->canCreate($member);
    }
    
}

class ShopGalleryImage_Image extends Image { 
    
    public function generateResized($gd) {
        return $gd->resize(328,214);	
    }
      
    public function canView($member = null) {
        return true;
    }
    
    public function canCreate($member = null) {
        if(!$member) $member = Member::currentUser();
        if(!$member) return false;
        return (
            Permission::checkMember($member, 'ADMIN')
            || Permission::checkMember($member, 'MANAGE_SHOPS')
        );
    }
    
    public function canEdit($member = null) {
        return $this->canCreate($member);
    }
 
    public function canDelete($member = null) {
        return $this->canCreate($member);
    }
}